package com.develop.jdbc.util;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

/**
 * @author fenny
 * @since 2019/6/2
 */
public class FileHelper {

    private static final Logger log = LoggerFactory.getLogger(FileHelper.class);

    public static void copyFile(File sourceFile, File targetFile) {
        try (FileInputStream input = new FileInputStream(sourceFile); BufferedInputStream inBuff = new BufferedInputStream(input); FileOutputStream output = new FileOutputStream(targetFile); BufferedOutputStream outBuff = new BufferedOutputStream(output)) {
            //缓冲数组
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1) {
                outBuff.write(b, 0, len);
            }
            //刷新此缓存的输出流
            outBuff.flush();
        } catch (Exception e) {
            log.error("", e);
        }
    }
}
